﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BookShop;
using SubSonic;

public partial class MessageHandle : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridView1.DataSource = new MessageController().FetchByReceiver(Profile.UserName);
            GridView1.DataBind();
        }
    }


    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "process")
        {
            // 获得对引发Command的控件的引用
            Control c = ((Control)e.CommandSource);
            // 获得该空间所在行(GridViewRow)的引用
            GridViewRow gvr = (GridViewRow)c.Parent.Parent;
            // 获取该行的主键值
            int key = 0;
            key = Convert.ToInt32(GridView1.DataKeys[gvr.RowIndex].Value);
            // 将该条信息的状态设为"Done"
            MessageController.SetMessageDone(key);
            string source = e.CommandArgument.ToString().Trim();
            string type = GridView1.Rows[gvr.RowIndex].Cells[3].Text.Trim();

            string url = new FlowProcess().GetNextDestination(type, source, Profile.StoreId);
            Response.Redirect(url);
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}
